//
//  ViewController.m
//  KVO--原理
//
//  Created by 岚海网络 on 2018/12/4.
//  Copyright © 2018年 岚海网络. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"


@interface ViewController ()

@property (nonatomic , strong) Person * person;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    _person = [[Person alloc] init];
    
    /* 注册 */
    [_person  addObserver:self  forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
    
}

#pragma mark - 监听方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
    NSLog(@"%@",change);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    static int a;
//    _person->_name = [NSString stringWithFormat:@"%d",a++];
    _person.name = [NSString stringWithFormat:@"%d",a++];
}


@end
